//
//  JSUsedWLViewCell.swift
//  fho
//
//  Created by 郭颢源 on 2021/5/29.
//

import UIKit

class JSUsedWLViewCell: UITableViewCell, UICollectionViewDelegate, UICollectionViewDataSource {
    
    
    var tui:[HandyJSON] = [] {
        didSet{
            let model = JSTuiModel()
            model.title = "当前常用"
            tui.append(model)
        }
    }
    
    let layout = JSCollectionViewLayout()
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        layout.ver_spacing = 0
        layout.hor_spacing = 0
        layout.numRow = 4
        layout.numCol = 4
        let collectionView = UICollectionView(frame: CGRect.zero, collectionViewLayout: layout);
        contentView.addSubview(collectionView)
        collectionView.snp.makeConstraints { (make) in
            make.edges.equalToSuperview()
        }
        collectionView.isUserInteractionEnabled = true
        collectionView.delegate = self
        collectionView.dataSource = self
        collectionView.register(JSUsedWLCell.self, forCellWithReuseIdentifier: "JSUsedWLCell")
        collectionView.isPagingEnabled = true
        collectionView.backgroundColor = .green
    }

    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    /**
     返回有几个分组
     */
    func numberOfSections(in collectionView: UICollectionView) -> Int
    {
        
        return 1
    }
    /**
     返回每个分组有几个数据
     */
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int{
        
//        return layout.numRow*layout.numCol
        return tui.count
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "JSUsedWLCell", for: indexPath) as! JSUsedWLCell
        let model = tui[indexPath.row] as! JSTuiModel
//        cell.imageView = model.companyName
        cell.titleLabel.text = model.title
        return cell
    }

    // MARK: 点击事件
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        
        let text = String(format: ("你点击了第 %d-%d 个cell"), arguments: [indexPath.section + 1, indexPath.row + 1])
        print(text)
        
    }
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
